//
//  TimerView.swift
//  CHT
//
//  Created by aiquantong on 2019/2/22.
//  Copyright © 2019 difan. All rights reserved.
//

import UIKit

class TimerView: UIView {

    public var curVal:Float = 0;
    public var maxVal:Float = 10000;
    
    
    /*
     Only override draw() if you perform custom drawing.
     An empty implementation adversely affects performance during animation.
     */
    override func draw(_ rect: CGRect) {
        let context : CGContext? = UIGraphicsGetCurrentContext();
        
        /*画圆*/
        context?.setStrokeColor(UIColor.green.cgColor);
        context?.setLineWidth(3.0);
    
        let curCol:Float = 2*Float(M_PI)*self.curVal/self.maxVal - Float(M_PI_2);
        if (self.maxVal < 1 || fabs(curCol + Float(M_PI_2)) < 0.01) {
            return;
        }
        
        context?.addArc(center: CGPoint(x:self.frame.size.width/2, y:self.frame.size.height/2),
                        radius: self.frame.size.width/2-2,
                        startAngle: CGFloat(-M_PI_2),
                        endAngle: CGFloat(curCol),
                        clockwise: false);
        
        context?.drawPath(using: CGPathDrawingMode.stroke);
    }
 

}
